package cn.edu.xjtu.competiton.力扣.周赛.weekly291;

/**
 * @author Hydrion-QLz
 * @date 2022-05-01 10:28
 * @description
 */
public class first {
    public static void main(String[] args) {
        first solution = new first();
        int[] arr = {};
        System.out.println(solution.removeDigit("1231", '1'));
    }

    public String removeDigit(String number, char digit) {
        int n = 0;
        for (int i = 0; i < number.length(); i++) {
            if (number.charAt(i) == digit) {
                n++;
            }
        }
        int delete = 0;
        for (int i = 0; i < number.length(); i++) {
            if (number.charAt(i) == digit) {
                n--;
                if (n == 0 || number.charAt(i) < number.charAt(i + 1)) {
                    delete = i;
                    break;
                }
            }
        }
        return number.substring(0, delete) + number.substring(delete + 1, number.length());
    }
}
